<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名" prop="nickname">
        <el-input v-model="queryParams.nickname" placeholder="请输入用户名" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="手机号" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入手机号" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="时间" style="width: 308px;">
        <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
          start-placeholder="开始时间" end-placeholder="结束时间"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['mobile:weekstat:export']">导出
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="statList" @selection-change="handleSelectionChange">
      <el-table-column label="主键ID" align="center" prop="id" v-if="false" />
      <el-table-column fixed label="用户名" align="center" prop="nickname" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="周次" align="center" prop="week" />
      <el-table-column label="统计时间" align="center" prop="statStartDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.statStartDate, '{y}-{m}-{d}') }} 至 {{ parseTime(scope.row.statEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="平均步数(日)" align="center" prop="steps" />
      <el-table-column label="平均消耗卡路里(千卡/天)" align="center" prop="calories" />
      
    </el-table>

    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script setup name="Stat">
import { listStat } from "@/api/mobile/weekstat";

const { proxy } = getCurrentInstance();

const statList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    nickname: null,
    phone: null
  },
  rules: {
    
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询华为健康每周统计数据列表 */
function getList() {
  loading.value = true;
  listStat(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
    statList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download('mobile/weekstat/export', {
    ...queryParams.value
  }, `stat_${new Date().getTime()}.xlsx`)
}


getList();
</script>
